<template>
	<div class="addbanner">
		<div>
			<h3>热点管理</h3>
			<p>描述：<input type="text" v-model="memo" /></p>
			<p>热度：<input type="text" v-model.number="hot" /></p>
			<p>类型：<input type="text" v-model.number="type" /></p>
			<p>图片：<input type="file" ref='imgUrl'/></p>
		</div>
		<hr />
		<el-button type='primary' size="small"><router-link :to="{name:'banner'}">返回</router-link></el-button >
		<el-button type='primary' size="small" @click="upload()">上传</el-button>
	</div>
</template>

<script>
	export default {
		name:'AddbannerImg',
		data(){
			return{
				memo:'',
				hot:'',
				type:'',
			}
		},
		methods:{
			upload(){
				//获取第一张图片
				let imgObj = this.$refs.imgUrl.files[0];
				//FormData：用一些键值对来模拟一系列表单控件：即把form中所有表单元素的name与value组装成
				let fromdata = new FormData();
				if(this.memo!=''&&this.hot!=''&&this.type!=''){
					fromdata.append('memo',this.memo)
					fromdata.append('hot',this.hot)
					fromdata.append('type',this.type)
					fromdata.append('pic',imgObj)
					this.axios.post('/api/adm/hot/addHot',fromdata).then((res)=>{
						if(res.data.code===500){
							alert('系统错误')
						}else if(res.data.code===200){
							alert('添加成功')
						}
					}).catch((error)=>{
						console.log(error);
					})
					
				}
			}
		}
	}
</script>

<style scoped>
a{
	text-decoration: none;
	color: white;
}
.addbanner {
	width: 100%;
	height: 100%;
}
</style>
